from smtplib import SMTP_SSL
from email.mime.text import MIMEText
from email.header import Header


def sendMail(to_addrs, message):
    '''
    :param message: str 邮件内容
    :param Subject: str 邮件主题描述
    :param sender_show: str 发件人显示，不起实际作用如："xxx"
    :param recipient_show: str 收件人显示，不起实际作用 多个收件人用','隔开如："xxx,xxxx"
    :param to_addrs: str 实际收件人
    :param cc_show: str 抄送人显示，不起实际作用，多个抄送人用','隔开如："xxx,xxxx"
    '''
    # 填写真实的发邮件服务器用户名、密码
    # user = '860694896@qq.com'
    # password = 'nlqpueilnxlobahh'
    user = 'aks@shockactions.com'
    password = '5VFHGzaadmhe2QRy'
    Subject = '邮箱验证码'
    # 显示发送人
    sender_show = '艾克物联'
    # 邮件内容
    msg = MIMEText(message, 'html', _charset="utf-8")
    # 邮件主题描述
    msg["Subject"] = Header(Subject, 'utf-8')
    # 发件人显示，不起实际作用
    msg["from"] = Header(sender_show, 'utf-8')
    # 收件人显示，不起实际作用
    msg["to"] = Header(to_addrs, 'utf-8')
    # 抄送人显示，不起实际作用
    msg["Cc"] = ""
    with SMTP_SSL(host="smtp.exmail.qq.com", port=465) as smtp:
        # 登录发邮件服务器
        smtp.login(user=user, password=password)
        # 实际发送、接收邮件配置
        smtp.sendmail(from_addr=user, to_addrs=to_addrs.split(','), msg=msg.as_string())


if __name__ == '__main__':
    # 实际发给的收件人
    to_addrs = '18625550856@163.com,'
    message = 'Python 测试邮件...'
    sendMail(to_addrs, message)
